/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.base;

class CodeFactory {
	public Code create(String classPathEntry) {
		return isJar(classPathEntry) ? new Jar(classPathEntry) : new ClassDirectory(classPathEntry);
	}

	public Code[] create(String ... classPathEntries) {
		Code[] code = new Code[classPathEntries.length];

		int index = 0;
		for (String classPathEntry : classPathEntries) {
			code[index++] = create(classPathEntry);
		}

		return code;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Implementation methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	private boolean isJar(String classPathEntry) {
		return classPathEntry.endsWith(".jar") || classPathEntry.endsWith(".zip");
	}
}